<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="零售收银设置">

    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <script>
        jQuery(function () {
            fixTableOperatorButton();
        });

        layui.use(['form', 'table'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table;
            renderTable();

            table.on('tool(table)', function (obj) {
                var data = obj.data;
                switch(obj.event){
                    case 'edit':
                        openTab("编辑零售收银设置","${baseUrl}sett/retailSetEdit.action?id="+data.id);
                        break;
                    case 'delete':
                        del(data);
                        break;
                };
            });

            table.on('toolbar(table)', function (obj) {
                switch(obj.event){
                    case 'add':
                        openTab("新增零售收银设置","${baseUrl}sett/retailSetNew.action");
                        break;
                };
            });
        });

        function renderTable() {
            layui.table.render({
                id:'table'
                , elem: '#table'
                ,toolbar: '#tableToolBar'
                ,defaultToolbar:[]
                , url: "${baseUrl}sett/retailSet/getList.action?time="+(new Date()).valueOf()
                , limit: 10
                , page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                    //,curr: 5 //设定初始在第 5 页
                    ,groups: 5 //只显示 5 个连续页码
                    ,first: false //不显示首页
                    ,last: false //不显示尾页
                }
                , done: function(res, curr, count){

                }
                , cols: [[
                    {type:'numbers'},
                    {field: 'id', width: 10, title: 'ID',hide:true},
                    {field: 'store', width: 150, title: '门店',style:"font-size:12px;",
                        templet: function(d){
                            return d.store.name;
                        }
                    },
                    {field: 'house', width: 150, title: '出库仓库',style:"font-size:12px;",
                        templet: function(d){
                            return d.house.name;
                        }
                    },
                    {field: 'cashSettAccount',width: 150, title: '现金账户',style:"font-size:12px;",
                        templet: function(d){
                            return d.cashSettAccount==null?"":d.cashSettAccount.name;
                        }
                    },
                    {field:"cardSettAccount",width: 150, title: '银行卡账户',style:"font-size:12px;",
                        templet: function(d){
                            return d.cardSettAccount==null?"":d.cardSettAccount.name;
                        }
                    },
                    {field:"custom",width: 150, title: '默认客户',style:"font-size:12px;",
                        templet: function(d){
                            return d.custom.name;
                        }
                    },
                    {title: '操作', minWidth: 80, fixed:'right', templet: '#operBar'},
                ]]
            });
        }

        function del(data) {
            layer.confirm('删除?', {icon: 3, title:'删除零售设置'}, function(index){
                tipLoad();
                post("${baseUrl}sett/retailSet/delete.action",{id:data.id}, function (res) {
                    closeLoading();
                    if (res.code == 1){
                        tip("删除成功");
                        renderTable();
                    } else {
                        tip(res.msg);
                    }
                });
            });
        }
    </script>

</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <table class="layui-hide" id="table" lay-filter="table"></table>

        <script type="text/html" id="tableToolBar">
            <div class="layui-inline">
                <a class="layui-btn" lay-event="add">新增</a>
            </div>
        </script>

        <script type="text/html" id="operBar">
            <a class="layui-btn layui-btn-xs table-operator" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger table-operator" lay-event="delete">删除</a>
        </script>
    </div>
</div>

</body>

<html:loading tip="处理中,请稍后..."/>
</html>